package com.example.itshome.network;

import android.app.Activity;
import com.example.itshome.manager.UserInfoManager;
import org.json.JSONException;
import org.json.JSONObject;

public class ChangeIntroductionRequest extends AbstractNetworkRequest{
    private String introduction;

    public ChangeIntroductionRequest setIntroduction(String introduction) {
        this.introduction = introduction;
        return this;
    }
    public ChangeIntroductionRequest(Activity activity) {
        super(activity);
    }

    @Override
    protected String getPathAndParams() {
        return "user/set-info?username="+ UserInfoManager.getInstance().getUser().getUsername()+"&info="+introduction;
    }

    @Override
    protected void handleResult(String result) {
        try {
            JSONObject jsonObject=new JSONObject(result);
            int code= jsonObject.getInt("code");
            if(code!=200){
                return;
            }
            UserInfoManager.getInstance().getUser().setIntroduction(introduction);
            setHandleResultRunnable(new Runnable() {
                @Override
                public void run() {
                    UserInfoManager.getInstance().callRunner();
                    activity.finish();
                }
            });
        } catch (JSONException e) {
            e.printStackTrace();
        }

    }
}
